package list.web;

import list.dao.UserDao;
import list.dao.UserDaoImpl;
import list.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Administrator
 * @Date 2020/6/16 16:36
 **/
@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       /*1、获取请求参数id
         2、调用dao方法，根据id得到user对象
         3、将user对象保存在request域
         4、转发到upadate.jsp（页面取出request域中信息，显示数据）
        */
       String ids = request.getParameter("id");
       int id =Integer.parseInt(ids);
        UserDao dao=new UserDaoImpl();
        User user = dao.findByUser(id);
        /*保存在request域*/
        request.setAttribute("user",user);
        request.getRequestDispatcher("/list/update.jsp").forward(request,response);

    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPut(request, response);
    }
}
